package com.zengge.zbc.mapper;

import com.zengge.zbc.dto.Device;
import com.zengge.zbc.po.DeviceInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DeviceInfoMapper {


    @Select("SELECT * FROM device_info WHERE room_obj_id=#{roomObjId}")
    @Results(id = "device_info", value = {
            @Result(id = true, column = "object_id", property = "objectId"),
            @Result(column = "device_name", property = "deviceName"),
            @Result(column = "mac_address", property = "macAddress"),
            @Result(column = "room_obj_id", property = "roomObjId"),
            @Result(column = "device_cct", property = "deviceCct"),
            @Result(column = "device_Brightness", property = "deviceBrightness"),
            @Result(column = "device_type", property = "deviceType")
    })
    List<DeviceInfo> findDeviceInfoListByRoomObjId(@Param("roomObjId") long roomObjId);

    @Select("<script>SELECT * FROM device_info WHERE room_obj_id IN " +
            "<foreach collection='roomObjIds' item='roomObjId' index='index' open='(' separator=',' close=')'>#{roomObjId}" +
            "</foreach></script>")
    @ResultMap("device_info")
    List<DeviceInfo> findDeviceInfoListByRoomObjIds(@Param("roomObjIds") List<Long> roomObjIds);


    @Select("SELECT * FROM device_info WHERE object_id=#{objectId}")
    @ResultMap("device_info")
    DeviceInfo findDeviceInfoByObjectId(@Param("objectId") long objectId);

    //    @Insert("INSERT INTO device_info (object_id,device_name,mac_address,room_obj_id) " +
//            "VALUES(#{objectId},#{deviceName},#{macAddress},#{roomObjId})")
    @Insert("INSERT INTO device_info (object_id,device_name,mac_address,room_obj_id,device_cct,device_Brightness,device_type) " +
            "VALUES(#{objectId},#{deviceName},#{macAddress},#{roomObjId},#{deviceCct},#{deviceBrightness},#{deviceType})")
    void save(DeviceInfo deviceInfo);


    //    @Update("UPDATE device_info SET device_name=#{deviceName} WHERE object_id=#{objectId}")
    @Update("UPDATE device_info SET device_name=#{deviceName}, device_type=#{deviceType}, device_cct=#{deviceCct}, device_Brightness=#{deviceBrightness} WHERE object_id=#{objectId}")
    void update(DeviceInfo deviceInfo);

    @Delete("DELETE FROM device_info WHERE object_id=#{objectId}")
    void delete(DeviceInfo deviceInfo);
}
